/*
 * Copyright (c) 2022-2022 All rights Reserved.
 */

package com.driving.core.service.dto;

import java.security.GeneralSecurityException;

import com.driving.core.base.AbstractDTO;
import com.driving.core.entity.Student;
import com.driving.core.exception.DrivingException;
import com.driving.core.mapper.type.Gender;
import com.driving.core.util.PasswordEncryption;

import lombok.Getter;
import lombok.Setter;

/**
 * @author SAGITTAR
 * @since 2017
 */
@Getter
@Setter
public class StudentDTO extends AbstractDTO {

    private String nickName;

    private String mobile;

    private Gender gender;

    private String email;

    /**
     * 密码或新密码
     */
    private String password;

    /**
     * 旧密码
     */
    private String oldPassword;

    public Student toStudent() {
        Student student = new Student();
        student.setId(getId());
        student.setNickName(nickName);
        student.setGender(gender);
        student.setEmail(email);
        student.setMobile(mobile);
        try {
            student.setPassword(PasswordEncryption.getEncryptedPassword(password));
        } catch (GeneralSecurityException e) {
            throw new DrivingException(e);
        }
        return student;
    }
}
